package com.easysoft.commons.utils;

import java.util.HashMap;
import java.util.Map;

public class ParamUtils {

	private static final String regex = "[0-9]";

	/**
	 * 车源查询条件
	 * 
	 * @param param
	 * @return
	 */
	public static Map<String, String> split(String param) {

		Map<String, String> parameter = new HashMap<String, String>();

		int length = param.length();

		String strKey = new String(param);
		strKey = strKey.replaceAll(regex, "");

		char[] keys = strKey.toCharArray();

		if (keys.length > 0) {
			int beginIndex = param.indexOf(keys[0]);
			int endIndex = length;

			String value = null;
			for (int i = 0; i < keys.length; i++) {
				if (i + 1 < keys.length) {
					endIndex = param.indexOf(keys[i + 1]);
				}

				if (endIndex == -1 || beginIndex == endIndex) {
					value = param.substring(beginIndex + 1);
				}
				else {
					value = param.substring(beginIndex + 1, endIndex);
					beginIndex = endIndex;
				}

				parameter.put(String.valueOf(keys[i]), value);
			}
		}

		return parameter;
	}

	public static void main(String args[]) {
		String str = "a111k1k2k3k4k5k6k17c333";
		System.out.println(split(str));
		
		str = "111b222c333";
		System.out.println(split(str));
	}
}